package com.wordpress.fatecode.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.wordpress.fatecode.entity.Contato;
import com.wordpress.fatecode.jdbc.Conexao;

public class ContatoDAO implements DAO<Contato>{
	private Connection connection;
	private PreparedStatement stmt;
	private ResultSet result;
	
	@Override
	public void salvar(Contato e) {
		connection = new Conexao().getConnection();
		try {
			stmt = connection.prepareStatement("INSERT INTO CONTATO(?, ?, ?, ?, ?)");
			// inser contato
			stmt.setString(1, e.getTelefone());
			stmt.setString(2, e.getTelefoneComercial());
			stmt.setString(3, e.getCelular());
			stmt.setString(4, e.getFax());
			stmt.setString(5, e.getEmail());
			
			stmt.execute();
			
			close();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		

	}
	@Override
	public void alterar(Contato e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void excluir(long id) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public Contato buscar(long id) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public List<Contato> listar() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void cadastrar(Contato e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void close() {
		try {
			if (result != null)
				result.close();

			if (stmt != null)
				stmt.close();

			if (connection != null)
				connection.close();

		} catch (SQLException ex) {
			ex.printStackTrace();
		}
		
	}
	
	
}
